/*
 * 	Additional function for tables.html
 *	Written by ThemePixels	
 *	http://themepixels.com/
 *
 *	Copyright (c) 2012 ThemePixels (http://themepixels.com)
 *	
 *	Built for Amanda Premium Responsive Admin Template
 *  http://themeforest.net/category/site-templates/admin-templates
 */
jQuery(document).ready(function(){
	// Set up the chart
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column',
            margin: 75,
            options3d: {
                enabled: true,
                alpha: 15,
                beta: 15,
                depth: 50,
                viewDistance: 25
            }
        },
        title: {
            text: '最火教室Top10'
        },
        plotOptions: {
            column: {
                depth: 25
            }
        },
        yAxis: { min: 0, title: { text: '预定数量' } },
        series: [{
        	name:'教室名字'
        }]
    });

    // Activate the sliders
    jQuery('#R0').on('change', function(){
        chart.options.chart.options3d.alpha = this.value;
        showValues();
        chart.redraw(false);
    });
    jQuery('#R1').on('change', function(){
        chart.options.chart.options3d.beta = this.value;
        showValues();
        chart.redraw(false);
    });

    function showValues() {
    	jQuery('#R0-value').html(chart.options.chart.options3d.alpha);
    	jQuery('#R1-value').html(chart.options.chart.options3d.beta);
    }
    showValues();
    
	jQuery("#startDate").datepicker({ dateFormat: 'yy-mm-dd' });
	jQuery("#endDate").datepicker({ dateFormat: 'yy-mm-dd' });
	jQuery.ajax({
    	type:"get",
    	dataType:"json",
    	url:"/cms/order/hotClassrooms",
    	data:{startDate:'', endDate:''},
    	async:true,
    	success:function(data) {
    		chart.xAxis[0].setCategories(data.rooms);
    		chart.series[0].setData(data.counts);
    	}
    });
	
    
    jQuery("#search_form").submit(function(e){
	    e.preventDefault();
	});
    
    jQuery("#submit").click(function() {
    	var startDate = jQuery("#startDate").val();
    	var endDate = jQuery("#endDate").val();
    	jQuery.ajax({
        	type:"get",
        	dataType:"json",
        	url:"/cms/order/hotClassrooms",
        	async:true,
        	data:{startDate:startDate, endDate:endDate},
        	success:function(data) {
        		chart.xAxis[0].setCategories(data.rooms);
        		chart.series[0].setData(data.counts);
        	}
        });
    })
});